//
//  FirstViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/30.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "FirstViewController.h"
#import "SecondViewController.h"
#import "RentVieitor.h"
#import "CompanyAuViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController {
    
    NSInteger selectIndex;
}


- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;

}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    selectIndex = 100;
    self.title = @"经纪人认证";
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatLeftView];
    
    }

- (void)creatLeftView {
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 120)];
    headView.backgroundColor = [Utils colorConvertFromString:@"#1fae0c"];
    [self.view addSubview:headView];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, KWidth-200, 40)];
    label.text = @"经纪人认证";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:17];
    label.textColor = [UIColor whiteColor];
    [headView addSubview:label];
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(15, 20+12, 100,30);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 10, 90)];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左-left"] forState:UIControlStateHighlighted];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左-left"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:leftBtn];
    
    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(KWidth-65, 20+10, 50, 20);
    [rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(saveAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:rightBtn];
    
    UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, KWidth, KWidth*120/816)];
    imgview.image = [UIImage imageNamed:@"first-bd"];
    [headView addSubview:imgview];
    
    UILabel *firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 140, KWidth, 20)];
    firstLabel.text = @"第一步  认证信息";
    firstLabel.textAlignment = NSTextAlignmentCenter;
    firstLabel.font = [UIFont systemFontOfSize:17];
    firstLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    [self.view addSubview:firstLabel];
    
    UILabel *secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 170, KWidth, 13)];
    secondLabel.text = @"请选择您的角色类型,一旦成功建立账号";
    secondLabel.textAlignment = NSTextAlignmentCenter;
    secondLabel.font = [UIFont systemFontOfSize:13];
    secondLabel.textColor = [Utils colorConvertFromString:@"#666666"];
    [self.view addSubview:secondLabel];
    
    UILabel *thirstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,190 , KWidth, 13)];
    thirstLabel.text = @"类型不可更改";
    thirstLabel.textAlignment = NSTextAlignmentCenter;
    thirstLabel.font = [UIFont systemFontOfSize:13];
    thirstLabel.textColor = [Utils colorConvertFromString:@"#666666"];
    [self.view addSubview:thirstLabel];

    
    CGFloat heiht = 120;
    NSArray *imgArray = @[@"",@"authentication-img_01"];
    NSArray *imgArray2 = @[@"公司",@"人-认证"];
    NSArray *titleArray = @[@"我是中国境内符合法律的有正规资历的中介或托管公司",@"我是包括独立经济人和在中介,托管公司任职的员工"];
    for (int i=0; i<imgArray.count; i++) {
        
        UIImageView *selectView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 223+(heiht+15)*i, KWidth-30, 120)];
        selectView.userInteractionEnabled = YES;
        selectView.backgroundColor = [Utils colorConvertFromString:@"#1fae0c"];
        selectView.image = [UIImage imageNamed:imgArray[i]];
        selectView.layer.masksToBounds = YES;
        selectView.layer.cornerRadius = 2.5;
        [self.view addSubview:selectView];
        selectView.tag = 100+i;
        //添加手势
        UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView:)];
        PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
        PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
        [selectView addGestureRecognizer:PrivateLetterTap];
        
        UIImageView *logView = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, 40, 40)];
        logView.image = [UIImage imageNamed:imgArray2[i]];
        [selectView addSubview:logView];
        
        UILabel *contenrLabel = [[UILabel alloc] initWithFrame:CGRectMake(85,30, KWidth-85-30-30, 40)];
        contenrLabel.text = titleArray[i];
        contenrLabel.textAlignment = NSTextAlignmentLeft;
        contenrLabel.font = [UIFont systemFontOfSize:14];
        contenrLabel.numberOfLines = 0;
        contenrLabel.textColor = [UIColor whiteColor];
        [selectView addSubview:contenrLabel];
        
        
        //分割线
        CALayer *MlineLayer5 = [CALayer layer];
        MlineLayer5.backgroundColor = [[Utils colorConvertFromString:@"#cfcfcf"] CGColor];
        MlineLayer5.frame = CGRectMake(30 ,80, KWidth-30-60,1);
        MlineLayer5.backgroundColor = [UIColor whiteColor].CGColor;
        [selectView.layer addSublayer:MlineLayer5];
        
        UILabel *btnLabel = [[UILabel alloc] initWithFrame:CGRectMake(30,90, KWidth-30-60, 20)];
        btnLabel.text = @"立即申请>>";
        btnLabel.textAlignment = NSTextAlignmentCenter;
        btnLabel.font = [UIFont boldSystemFontOfSize:14];
        btnLabel.textColor = [UIColor whiteColor];
        [selectView addSubview:btnLabel];
        
        
        
    }
    
}

- (void)tapAvatarView:(UIGestureRecognizer *)recoger {
    
    UIImageView *comImgView = (UIImageView *)[self.view viewWithTag:100];
    UIImageView *perImgView = (UIImageView *)[self.view viewWithTag:101];
    if (recoger.view.tag == 100) {
        

        comImgView.image = [UIImage imageNamed:@""];
        perImgView.image = [UIImage imageNamed:@"authentication-img_02"];
        selectIndex = 100;
    }else {
        
        comImgView.image = [UIImage imageNamed:@"authentication-img_02"];
        perImgView.image = [UIImage imageNamed:@""];
        selectIndex = 101;
    }
    
    
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)saveAction {
    
    
    if (selectIndex == 100) {
        
        
        CompanyAuViewController *comVc = [[CompanyAuViewController alloc] init];
        [self.navigationController pushViewController:comVc animated:YES];
        return;
    }
    
    if (selectIndex == 101) {
        
        SecondViewController *sendVc = [[SecondViewController alloc] init];
        [self.navigationController pushViewController:sendVc animated:YES];
        return;
    }
    
    
    
}
@end
